package com.ruoyi.web.controller.kyhs;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.kysh.entity.TaskPlan;
import com.ruoyi.system.kysh.entity.TeamClassInf;
import com.ruoyi.system.kysh.entity.dto.TaskPlanDto;
import com.ruoyi.system.kysh.service.TaskPlanService;
import com.ruoyi.system.kysh.service.TeamClassInfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/kyhs/task-inf-list")
public class TaskInfListController {

    @Autowired
    private TaskPlanService taskPlanService;

    @Autowired
    private TeamClassInfService teamClassInfService;

    @GetMapping
    public AjaxResult getTaskListByLogin(){
        //Long userId = SecurityUtils.getUserId();
        List<TaskPlan> taskPlans=taskPlanService.selectByUserId(3L);//userId
        return AjaxResult.success("操作成功",taskPlans);
    }

    @GetMapping("/task-inf")
    public AjaxResult getTaskInfListByLogin(){
        //Long userId = SecurityUtils.getUserId();
        List<TaskPlan> taskPlans=taskPlanService.selectListByUserId(3L);//userId
        return AjaxResult.success("操作成功",taskPlans);
    }

    @PostMapping
    public AjaxResult getTaskInfDetailByTicketNum(@RequestParam String ticketNum){
        TaskPlanDto taskPlanDto=taskPlanService.selectTaskInfDetailByTicketNum(ticketNum);
        if(taskPlanDto==null){
            return AjaxResult.error("工单编号不存在");
        }
        return AjaxResult.success("操作成功",taskPlanDto);
    }

    @GetMapping("/show-user-not-select")
    public AjaxResult getUserNotSelect(String deptName,String parentName){
        List<TeamClassInf> teamClassInfs=teamClassInfService.getUserInfNotSelect(deptName,parentName);
        return AjaxResult.success("操作成功",teamClassInfs);
    }

    @PostMapping("/save-user")
    public AjaxResult saveUser(@RequestParam Long taskId, @RequestParam String deptName
            , @RequestParam String parentName, @RequestBody List<Long> userId){
        teamClassInfService.saveUsersByDeptId(taskId,deptName,parentName,userId);
        return AjaxResult.success("添加成功");
    }

    @GetMapping("/show-user-by-taskid")
    public AjaxResult getUserInfByTaskId(Long taskId){
        if(taskId==null){
            return AjaxResult.warn("请输入任务id");
        }
        List<TeamClassInf> teamClassInfs=teamClassInfService.getUserInfByTaskId(taskId);
        return AjaxResult.success("操作成功",teamClassInfs);
    }

    @PostMapping("/bind-by-task")
    public AjaxResult bindVideoByTaskId(@RequestParam Long taskId,@RequestParam String videoLoc){
        if(taskId==null){
            return AjaxResult.warn("请输入任务id");
        }
        taskPlanService.bindVideoByTaskId(taskId,videoLoc);
        return AjaxResult.success("绑定成功");
    }



}
